//
// Created by neo on 10/21/17.
//


#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>


const  long ARRAY_SIZE = 10;

int int_a;

struct {
    int a;
    char * b;
} x;

typedef struct SIMPLE {
    int a;
    char * b;
} type_simple;




int struct_test(){

    struct SIMPLE x;
    type_simple y;
    type_simple * tx;
    type_simple * ty;



    x.a = 10;
    x.b = "apple";

    y.a = 5;
    y.b = "Hello world";

    tx  = &x;
    ty = &y;
    printf("%d  %s\n",tx->a,tx->b);
    printf("%d  %s\n",ty->a,ty->b);


    type_simple array_simple [10];

    array_simple[0] = x;
    array_simple[1] = y;

    printf("%d %s\n",array_simple[0].a,array_simple[0].b);


    type_simple * point_array_simple [10];

    point_array_simple[0] = tx;
    point_array_simple[1] = ty;


    printf("%d %s\n",point_array_simple[0]->a,point_array_simple[1]->b);



    type_simple * simple =  (type_simple *)malloc(sizeof(type_simple));

    simple->a = 5;
    simple->b = "Hello poing";
    printf("%d %s\n",simple->a,simple->b);

    free(simple);



    type_simple * simple_arry [ARRAY_SIZE] ;

    printf("init the memory of the point array\n");
    for(int i = 0; i< ARRAY_SIZE; i++){

        simple_arry[i] = (type_simple *)malloc(sizeof(type_simple));
    }

    printf("init the value of the point array\n");
    for(int i = 0; i < ARRAY_SIZE; i ++){
        (* simple_arry[i]).a = i * 10;
        simple_arry[i]->b = "Hello";

    }

    printf("output the value of the point array\n");
    for(int i = 0; i < ARRAY_SIZE ; i++ ){
        printf("%d %s\n",simple_arry[i]->a,(* simple_arry[i]).b);
    }

    printf("release the memory space of the simple_array \n");
    for(int i = 0; i < ARRAY_SIZE ; i++){
        free(simple_arry[i]);
    }
}

int main_struct(int argc, char ** argv){
    char * string = "Hello world !";
    printf("%s\n",string);
    printf("结构类型的定义\n");
    struct_test();


}
